﻿@{
    ViewBag.Title = "省份管理";
    Layout = "~/Areas/Admin/Views/Shared/_Layout.cshtml";
}
<style type="text/css">
    .layout-split-west {
        border-right-color: Window;
    }
</style>
<div class="easyui-layout" data-options="fit:true" scroll="no">
    <div data-options="region:'center',noheader:true,border:false">
        <table id="dgProvince"></table>
    </div>
</div>
<div id="tbar">
    <div class="tbar">
        <div class="z-toolbar">
            <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-arrow_refresh',plain:true" onclick="ToolbarRefresh();">刷新</a>
            <div class="datagrid-btn-separator"></div>
            <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" onclick="ToolbarAdd();">增加</a>
            <div class="datagrid-btn-separator"></div>
            <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true" onclick="ToolbarEdit();">编辑</a>
            <div class="datagrid-btn-separator"></div>
            <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-cross',plain:true" onclick="ToolbarRemove();">删除</a>
            <div class="datagrid-btn-separator"></div>
            <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true" onclick="ToolbarUnselect();">取消选中</a>
        </div>
    </div>
</div>
@section PageSpecificScript{
    <script type="text/javascript">
        var dgProvince;/*显示省份*/
        var editRow = undefined;
        var searchForm;
        $(document).ready(function () {
            earchForm = $("#searchForm");
            $.validateUrl("/Admin/Sys_Province/GetProByCondition", function () {
                dgProvince = $("#dgProvince").datagrid({
                    url: '/Admin/Sys_Province/GetProByCondition',
                    method: 'get',
                    idField: 'PId',
                    fit: true,
                    fitColumns: true,
                    rownumbers: true,
                    striped: true,
                    pagination: true,
                    singleSelect: true,
                    toolbar: '#tbar',
                    pageSize: 20,
                    pageList: [10, 20, 30, 40, 50],
                    columns: [[
                        { field: 'PId', title: 'PId', hidden: true },
                        { field: 'PName', title: '省份名称', width: 100, halign: 'center', align: 'center' },
                        { field: 'PCode', title: '省份编码', width: 100, halign: 'center' }
                    ]],
                    onDblClickRow: function (rowIndex, rowData) {
                        if (editRow != undefined) {
                            dgProvince.datagrid('endEdit', editRow);
                        } else {
                            dgProvince.datagrid('beginEdit', rowIndex);
                            editRow = rowIndex;
                            dgProvince.datagrid('selectRow', editDictValue);
                        }
                    },
                    onRowContextMenu: function (e, rowIndex, rowData) {
                        e.preventDefault();
                        $(this).datagrid("unselectAll");
                        $(this).datagrid("selectRow", rowIndex);
                        $("#menu").menu('show', {
                            left: e.pageX,
                            top: e.pageY
                        });
                    }
                });
            });
        }, xz.dealWith, 'GET');
        /**刷新菜单**/
        function ToolbarRefresh() {
            dgProvince.datagrid("load");
        }
        /**增加菜单**/
        function ToolbarAdd() {
            showAppendView();
        }
        /**编辑菜单**/
        function ToolbarEdit() {
            showEditView();
        }
        /**删除菜单**/
        function ToolbarRemove() {
            removeDictValue();
        }
        /**取消选中菜单**/
        function ToolbarUnselect() {
            dgProvince.datagrid("unselectAll");
        }
        /*打开添加权限信息的页面*/
        function showAppendView() {
            $.validateUrl('/Admin/Sys_Dict/EditView', append, xz.dealWith, 'GET');
        }
        /*增加字典信息*/
        function append() {
            var node = deptTree.tree("getSelected");
            if (node) {
                var pAdd = xz.dialog({
                    title: '新增字典',
                    width: 680,
                    height: 300,
                    iconCls: 'icon-add',
                    href: '/Admin/Sys_Dict/EditView',
                    buttons: [{
                        text: '新增',
                        iconCls: 'icon-add',
                        handler: function () {
                            var f = pAdd.find('form');
                            f.form('submit', {
                                url: '/Admin/Sys_Dict/AddDictValue',
                                success: function (jsonData) {
                                    jsonData = $.parseJSON(jsonData);
                                    $.procAjaxMsg(jsonData, function () {
                                        pAdd.dialog('close');
                                        dgProvince.datagrid("reload");
                                        $.alertMsg(jsonData.Msg, "操作提示", null);
                                    }, function () {
                                        $.alertMsg(jsonData.Msg, "操作提示", null);
                                    });
                                }
                            });
                        }
                    }, {
                        text: '关闭',
                        iconCls: 'icon-cancel',
                        handler: function () {
                            pAdd.dialog('close');
                        }
                    }],
                    onLoad: function () {
                        var f = pAdd.find('form');
                        var keyID = f.find('input[name=KeyID]');
                        var keyName = f.find('input[name=KeyName]');

                        f.form('load', {
                            KeyID: node.id,
                            KeyName: node.text
                        });
                    }
                })
            } else {
                xz.messagerAlert("提示", "请选择左侧要添加的关键字", "error");
            }
        }
        /*编辑字典信息*/
        function showEditView() {
            $.validateUrl('/Admin/Sys_Dict/EditView', edit, xz.dealWith, 'Get');
        }
        /*修改字典*/
        function edit() {
            var node = dgProvince.datagrid("getSelected");
            if (node) {
                var pAdd = xz.dialog({
                    title: '修改字典',
                    width: 680,
                    height: 320,
                    iconCls: 'icon-edit',
                    href: '/Admin/Sys_Dict/EditView',
                    buttons: [{
                        text: '修改',
                        iconCls: 'icon-edit',
                        handler: function () {
                            var f = pAdd.find('form');
                            f.form('submit', {
                                url: '/Admin/Sys_Dict/EditDictValue',
                                success: function (jsonData) {
                                    jsonData = $.parseJSON(jsonData);
                                    $.procAjaxMsg(jsonData, function () {
                                        pAdd.dialog('close');
                                        dgProvince.datagrid("reload");
                                        $.alertMsg(jsonData.Msg, "操作提示", null);
                                    }, function () {
                                        $.alertMsg(jsonData.Msg, "操作提示", null);
                                    });
                                }
                            });
                        }
                    }, {
                        text: '关闭',
                        iconCls: 'icon-cancel',
                        handler: function () {
                            pAdd.dialog('close');
                        }
                    }],
                    onLoad: function () {
                        var f = pAdd.find('form');
                        var valName = f.find('input[name=ValName]');

                        window.setTimeout(function () {
                            valName.focus();
                        }, 100);

                        /*把选中的组织机构信息绑定到对应的表单上*/
                        f.form('load', node);
                    }
                })
            } else {
                xz.messagerAlert("提示", "请选择要修改的字典", "error");
            }
        }

        /*删除字典*/
        function removeDictValue() {
            var rows = dgProvince.datagrid("getSelected");
            if (rows) {
                xz.messageConfirm('询问', '你确定要删除【' + rows.ValName + '】吗?', function (b) {
                    if (b) {
                        $.ajax({
                            type: 'POST',
                            url: '/Admin/Sys_Dict/DelDictValue',
                            data: {
                                valID: rows.ValID
                            },
                            cache: false,
                            dataType: 'JSON',
                            success: function (jsonData) {
                                $.procAjaxMsg(jsonData, function () {
                                    dgProvince.datagrid("reload");
                                    $.alertMsg(jsonData.Msg, "操作提示", null);
                                }, function () {
                                    $.alertMsg(jsonData.Msg, "操作提示", null);
                                });
                            }
                        });
                    }
                });
            }
        }
</script>

}

